﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinformCalculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int operand1;
            int.TryParse(textBox1.Text, out operand1);

            char @operator;
            char.TryParse(textBox2.Text, out @operator);

            int operand2;
            int.TryParse(textBox3.Text, out operand2);

            switch (@operator)
            {
                case '+':
                    Console.WriteLine(operand1 + " " + @operator + " " + operand2 + " = " + (operand1 + operand2));
                    answer.Text = (operand1 + operand2).ToString();
                    break;
                case '-':
                    Console.WriteLine(operand1 + " " + @operator + " " + operand2 + " = " + (operand1 - operand2));
                    answer.Text = (operand1 - operand2).ToString();
                    break;
                case '*':

                    Console.WriteLine(operand1 + " " + @operator + " " + operand2 + " = " + (operand1 * operand2));
                    answer.Text = (operand1 * operand2).ToString();
                    break;
                case '/':
                    Console.WriteLine(operand1 + " " + @operator + " " + operand2 + " = " + (operand1 / operand2));
                    answer.Text = (operand1 / operand2).ToString();
                    break;
                default:
                    answer.Text = "请输入有效运算符";
                    break;
            }
        }
    }
}
